Start parallel exeuction of multiple asynchronous actions.
Syntax
Parameters
- asyncFns
- List of asynchronous functions
- completedHandler
- Optional completion handler
Return Value
A CoroutineOperation representing this operation
Example
C# | Copy Code |
---|
public void CoroutineSampleParallel() {
// Start some parallel async operations.
var op = Coroutine.StartParallel(SampleActions);
// Listen for completion.
op.Completed += (s, e) => {
MessageBox.Show(e.Notifications.Count.ToString() + " operations completed");
// You can loop thru notifications for results from each operation.
};
}
// A block of asynchronous actions to be performed in parallel.
private IEnumerable<INotifyCompleted> SampleActions() {
// Start a query for all customers in specified country.
yield return _entityManager.Customers.Where(c => c.Country == "UK").ExecuteAsync();
// Start another query for all employees. This will run in parallel.
yield return _entityManager.Employees.ExecuteAsync();
}
/***************************************************************************************/
// Sample 2 - passing arguments to an iterator
public void CoroutineSampleParallel2() {
// Start some parallel async operations.
var op = Coroutine.StartParallel(() => SampleActions2("UK"));
// Listen for completion.
op.Completed += (s, e) => {
MessageBox.Show(e.Notifications.Count.ToString() + " operations completed");
// You can loop thru notifications for results from each operation.
};
}
// A block of asynchronous actions to be performed in parallel.
private IEnumerable<INotifyCompleted> SampleActions2(string country) {
// Start a query for all customers in specified country.
yield return _em1.Customers.Where(c => c.Country == country).ExecuteAsync();
// Start another query for all employeesin specified country. This will run in parallel.
yield return _em1.Employees.Where(e=> e.Country == country).ExecuteAsync();
} |
Remarks
Requirements
Target Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family
See Also